import { configureStore } from '@reduxjs/toolkit'
import createSagaMiddleware from 'redux-saga';
import { createReduxHistory, routerMiddleware } from '../history';
import createRootReducer from '@/reducers/index';
import rootSaga from '@/sagas/index';

// 引入工具插件
const sagaMiddleware = createSagaMiddleware();

const middleWare = [
  sagaMiddleware,
  routerMiddleware,
]
export const store = configureStore(
  {
    reducer: createRootReducer,
    middleware: middleWare,
  }
)
export const history = createReduxHistory(store);
export default function getStore() {
  sagaMiddleware.run(rootSaga)
  return store
}